package com.project.common.core.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * 手机号归属地查询
 *
 * @Author: wyy
 * @Date: 4/14/21 12:27 PM
 */
public class PhoneUtil {
    public static String getLocationOfPhone(String phoneNum) {
        String uri = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("tel", phoneNum);
        String locationStr = HttpUtil.get(uri, paramMap);
        int i = locationStr.indexOf("=");
        String locationJsonStr = locationStr.substring(i + 1);
        JSONObject locationJson = JSONObject.parseObject(locationJsonStr);
        String province = locationJson.getString("province");
        return province;
    }

    public static void main(String[] args) {
        String locationOfPhone = getLocationOfPhone("13805476323");
        System.out.println(locationOfPhone);
    }
}
